class code1 {
    //字母大小写全排列
    StringBuffer path;
    List<String> ret;
    public List<String> letterCasePermutation(String s) {
        ret = new ArrayList<>();
        path = new StringBuffer();

        dfs(s,0);
        return ret;
    }
    //决策树
    void dfs(String s,int pos) {
        //出口
        if(pos==s.length()) {
            ret.add(path.toString());
            return;
        }
        //核心
        //不变
        char ch = s.charAt(pos);
        path.append(ch);
        pos++;
        dfs(s,pos);
        path.deleteCharAt(path.length()-1);//恢复现场
        pos--;
        //变(非数字)
        if(ch<'0' || ch>'9') {
            path.append(change(ch));
            pos++;
            dfs(s,pos);
            path.deleteCharAt(path.length()-1);
            pos--;
        }
    }
    char change(char ch) {
        if(ch>='a'&&ch<='z') ch-=32;
        else ch+=32;
        return ch;
    }
}
